﻿using System;
using Grundy.Common;
using Grundy.CryptographicServices;
using Grundy.Message;

namespace Grundy.Entity
{
    public static class EntityExtensionMethods
    {
        public static CustomerEntitlement ToCustomerEntitlement(this CustomerLicenseEntitlement cple)
        {
            try
            {
                return new CustomerEntitlement
                {
                    Id = Guid.NewGuid(),
                    Customer = new Customer { Id = cple.CustomerId, Name = cple.CustomerName },
                    LicenseEntitlements = new LicenseEntitlementCollection(
                                                                     new[] {new LicenseEntitlement
                                                                                 {
                                                                                     Id = cple.LicenseEntitlementId,
                                                                                     Node = new Node{Identifiers = cple.NodeIdentity},
                                                                                     CreatedOn = Clock.Instance.Utc,
                                                                                     License = cple.License,
                                                                                     Product = new Product{Id = cple.ProductId, Name = cple.CustomerName}
                                                                                 }})
                };
            }
            catch (Exception)
            {
                return null;
            }
            
        }
    }
}